package com.zero.zeroframe.v

import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.allen.library.SuperTextView
import com.allen.library.shape.ShapeButton
import com.bumptech.glide.Glide
import com.lxj.androidktx.core.load
import com.zero.zeroframe.ktx.roundText

/**
 * 自定义BindingAdapter
 */
object MyBindingAdapter {

    @BindingAdapter("rightString")
    @JvmStatic
    fun rightString(view: SuperTextView, string: String?) {
        view.setRightString(string)
    }

    @BindingAdapter("rightTextColor")
    @JvmStatic
    fun rightTextColor(view: SuperTextView, color: Int) {
        view.setRightTextColor(color)
    }

    @BindingAdapter("moneyText")
    @JvmStatic
    fun moneyText(view: TextView, money: Double?) {
        view.text = money?.roundText(2)
    }

    @BindingAdapter("numText")
    @JvmStatic
    fun numText(view: TextView, num: Int?) {
        view.text = num?.toString()?:"0"
    }

    @BindingAdapter("glideSrc")
    @JvmStatic
    fun glideSrc(view: ImageView, path: Any) {
        Glide.with(view.context).load(path).into(view)
    }

    @BindingAdapter("colorFilter")
    @JvmStatic
    fun colorFilter(view: ImageView, color: Int) {
        if (color == -1) view.clearColorFilter()
        else view.setColorFilter(color)
    }

    @BindingAdapter("shapeButtonStrokeColor")
    @JvmStatic
    fun shapeButtonStrokeColor(view: ShapeButton, color: Int) {
        view.shapeBuilder!!.setShapeStrokeColor(color).into(view)
    }

    @BindingAdapter("load")
    @JvmStatic
    fun load(view: ImageView, url: String?) {
        view.load(url)
    }

}